package com.bw.gmallpublishertest.controller;

import com.bw.gmallpublishertest.service.SugerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;

@RestController
public class SugerController {

    @Autowired
    private SugerService sugerService;

    @RequestMapping("/api/sugar/gmv")
    public String selectGmv(@RequestParam(value = "date",defaultValue = "0") int date) {

        /*
          {
          "status": 0,
          "msg": "",
          "data": 1201059.128122374
          }
         */



        if (date==0){
            date=getToday();
        }

        return "{" +
                "          \"status\": 0," +
                "          \"msg\": \"\"," +
                "          \"data\": "+sugerService.selectGmv(date).getGmv()+""+
                "          }";
    }

    private int getToday() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        String dataTime = sdf.format(System.currentTimeMillis());

        return Integer.valueOf(dataTime);
    }
}